package com.situ.cloud.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableOpenApi
public class UserSwaggerConfig {

    @Bean
    public Docket userApiDocket() {
        return new Docket(DocumentationType.OAS_30)
                .enable(true)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.situ.cloud.user.controller"))
                .paths(PathSelectors.any())
                .build().securitySchemes(myScheme());
    }

    private List<SecurityScheme> myScheme(){
        List<SecurityScheme> list = new ArrayList<>();
        list.add(new ApiKey("Authorization", "token", "header"));
        return list;
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("user服务接口文档")
                .description("这是一个文档的描述。。。。。")
                .version("1.0").build();
    }

}
